// JavaScript Document
function messageHandler(event) {
	var messageSent = event.data;
	var total =  2;
	outer: for(var n = 1; n < 300000; n++)
	{
		for(var i = 2; i < Math.sqrt(n); i += 1)
		{
			if(n % i == 0)
				continue outer;
		}
		total++;
		postMessage(total);
	}
//    // Accessing to the message data sent by the main page
//    var messageSent = event.data;
//    // Preparing the message that we will send back
//    var messageReturned = "Hello " + messageSent + " from a separate thread!";
//    // Posting back the message to the main page
//    this.postMessage(messageReturned);
}

// Defining the callback function raised when the main page will call us
this.addEventListener('message', messageHandler, false);

